TABLEMIN Function

Syntax

Smallest_Of_Values as A = TABLEMIN(C tablename,C filter,C field)

Arguments

tablename

The full drive, path, name, and extension of the table. If you omit the drive, path, and extension, Alpha Anywhere searches the directory of the current table.

filter

A character filter expression that evaluates to a logical value. Selects records to examine.

field

An expression based on character, numeric, date, or exponent numeric field(s) in the Lookup_Table.

Description

Returns the minimum value of matching records in a specified table.

Discussion

Searches the specified Lookup_Table for one or more records that satisfy the specified Filter, and returns the smallest of the values contained in the Lookup_Expression. The Filter must return a logical value, either True (.T.) or False (.F.). For example, to choose all of the records in a table, use the logical constant ".T." as a filter. To choose only the records where the STATE field is equal to TN, use the filter "STATE = 'TN'". Note that the entire filter is always in quotations, and the character value, TN, is in single quotes. Note : If no records satisfy the filter, Alpha Anywhere returns a zero value.

Assume that a department purchasing table (PURCHASE) contains the following records:

PURCHASE TABLE
>
MANAGER
COST, BILL_DATE, and PAID_UP
ANDRY

18500.00 01/01/2003 T

BROWN

49.95 02/01/2003 T

BROWN

12.99 04/01/2003 F

FARLEY

7995.00 03/01/2003 F

FARLEY

142.16 04/10/2003 T

FARLEY

423.00 05/10/2003 F

All Records

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table:

? TABLEMIN("PURCHASE.DBF",".T.","COST")
= 12.990000

Filter Using a Specific Character String

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where "Farley" is the manager:

? TABLEMIN("PURCHASE.DBF", "MANAGER = 'FARLEY'", "COST")
= 142.160000

Filter Using a Character Variable

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where the manager matches the character string previously assigned to the variable vManager.

? TABLEMIN("PURCHASE.DBF","Manager = '" + vManager + "' ","COST")
= 12.990000 ' if vManager is "BROWN"

Filter Using a Specific Number

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where the Cost is greater than 100.00.

? TABLEMIN("PURCHASE.DBF","Cost > 100.00", "COST")
= 142.160000

Filter Using Numeric Variable

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where the Cost is greater than whatever amount has been previously assigned to the numeric variable vCost.

? TABLEMIN("PURCHASE.DBF","Cost > " + vCost, "COST")
= Returns 7995.000000 ' if vCost = 1000.00

Filter Using a Specific Date Value

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where the Bill_Date is equal to or later than February 1, 2003.

? TABLEMIN("PURCHASE.DBF","BILL_DATE >= {02/01/2003}", "COST")
= 12.990000

Filter Using Date Variables

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where the Bill_Date is equal to or later than the date previously assigned to vBeginDate AND equal to or later than the date previously assigned to vEndDate :

? TABLEMIN("PURCHASE.DBF","BETWEEN(BILL_DATE,{" + DTOC(vBeginDate) + "},{" + DTOC(vEndDate) + "})", "COST")
49.950000 ' if vBeginDate is 01/01/2003 and vEndDate is 03/31/2003

Filter Using Logical Variables

The following expression returns the smallest of the values in the Cost field for all records in the Purchase table where Paid_Up is true:

? TABLEMIN("PURCHASE.DBF", "PAID_UP", "COST")
= 49.950000

While this expression returns the smallest of the values in the Cost field for all records in the Purchase table where Paid_Up is not true:

? TABLEMIN("PURCHASE.DBF", ".NOT. PAID_UP", "COST")
= 12.990000

Thanks to

Tom Cone

See Also